﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web;
namespace JTicket.UI.Extention.IHandler
{
    public class DrawSeateHandler : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }


        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string ex = request.QueryString["ex"].ToString();
            string ey = request.QueryString["ey"].ToString();
            string subcode = request.QueryString["subcode"].ToString();
            string subname = request.QueryString["subname"].ToString();
            string thcode = request.QueryString["thcode"].ToString();
            string areacode = request.QueryString["AreaCode"].ToString();
            if (!BLL.D_Area.Exists(subcode))
            {
                for (int i = 1; i <= (int.Parse(ex) * int.Parse(ey)); i++)
                {
                    BLL.D_SubArea.SeatCreate(i.ToString(), ex, ey, subcode, subname, thcode, areacode);
                }
            }
            else
            {
                BLL.D_Area.Deletes(thcode, subcode);
                for (int i = 1; i <= (int.Parse(ex) * int.Parse(ey)); i++)
                {
                    BLL.D_SubArea.SeatCreate(i.ToString(), ex, ey, subcode, subname, thcode, areacode);
                }
            }
        }
        #endregion
    }

    public class ExsitArea : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string subcode = request.QueryString["SubCode"].ToString();
            response.Write(BLL.D_Area.Exists(subcode).ToString());
            response.End();
        }
        #endregion
    }


    public class DrawGetHandler : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            int top = 0;
            int left = 0;
            StringBuilder sb = new StringBuilder();
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string subcode = request.QueryString["SubCode"].ToString();
            string thcode = request.QueryString["ThCode"].ToString();
            string Cow = request.QueryString["Cow"].ToString();
            int falg = (int.Parse(Cow) - 1) * 19;
            List<Model.SeatParm> list = BLL.D_SubArea.GetSeatMap(subcode, thcode);
            foreach (var model in list)
            {
                sb.Append("<div id=\"" + model.sixid + "\"");

                if (model.visible == "0")
                    sb.Append("style=\"background-color:#ffffff;");
                else
                {

                    if (model.color != "")
                        sb.Append("style=\"background-color:" + model.color + ";");
                    else
                        sb.Append("style=\"background-color:#ee845c;");
                }
                sb.Append("top:" + top + "px;");
                sb.Append("left:" + left + "px;font-size:12px;cursor:default; width:17px; height:17px;");
                sb.Append("margin:1px 1px 1px 1px;position:absolute;\" onmousedown=\"Choose(this);\"");
                sb.Append("onmouseover=\"if(!!isBound){Choose(this);}showTooltip('dHTMLToolTip',event, '<strong>");
                sb.Append(string.Format("子分区：</strong>{0}<br><strong>排号：</strong>{1}<br>", model.note, model.row));
                sb.Append(string.Format("<strong>座号：</strong>{0}<br><strong>描述：</strong>{1}<br>",model.cow,model.msg));
                sb.Append(string.Format("<strong>票类：</strong>{0}<br><strong>票价：</strong>{1}',", model.ticketname, model.price));
                sb.Append("'#F3F2E7','#000000','#000000','20000')\">"+model.cow+"</div>");
                if (left >= falg)
                {
                    top += 19;
                    left = 0;
                }
                else
                    left += 19;
            }
            response.Write(sb.ToString());
            response.End();
        }
        #endregion
    }
    /// <summary>
    /// 子分区Note
    /// </summary>
    public class DrawNote : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');
            string Note = request.QueryString["Note"].ToString();
            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        BLL.D_SetSubArea.updateNote(SubCode, SeatList[i], Note);
                    }
            }
        }
        #endregion
    }
    /// <summary>
    /// 排号
    /// </summary>
    public class DrawRow : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');
            string Row = request.QueryString["Row"].ToString();
            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        BLL.D_SetSubArea.updateRow(SubCode, SeatList[i], Row);
                    }
            }
        }
        #endregion
    }

    /// <summary>
    /// 座号
    /// </summary>
    public class DrawCow : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');
            string Cow = request.QueryString["Cow"].ToString();
            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        BLL.D_SetSubArea.updateCow(SubCode, SeatList[i], Cow);
                    }
            }
        }
        #endregion
    }

    /// <summary>
    /// 座位描述
    /// </summary>
    public class DrawMsg : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');
            string Msg = request.QueryString["Msg"].ToString();
            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        BLL.D_SetSubArea.updateMsg(SubCode, SeatList[i], Msg);
                    }
            }
        }
        #endregion
    }

    /// <summary>
    /// 颜色 票类名称 票类价格
    /// </summary>
    public class DrawPriceColor : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string Name = request.QueryString["Name"].ToString();
            string Price = request.QueryString["Price"].ToString();
            string Color = request.QueryString["Color"].ToString();
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');
            Model.D_SubAreaPrice nameprice = new Model.D_SubAreaPrice();
            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                {
                    nameprice.SubCode = SubCode;
                    nameprice.Color = Color;
                    nameprice.Price = Price;
                    nameprice.Ticketname = Name;
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        nameprice.SixID = SeatList[i].ToString();
                        BLL.D_SubAreaPrice.updateSubArea(nameprice);
                    }
                }
            }
        }
        #endregion
    }
    /// <summary>
    /// 显示
    /// </summary>
    public class DrawShow : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {

            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');
             
            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        BLL.D_SetSubArea.updateShow(SubCode, SeatList[i]);
                    }
            }
        }
        #endregion
    }
    /// <summary>
    /// 隐藏
    /// </summary>
    public class DrawHide : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string SubCode = request.QueryString["SubCode"].ToString();
            string[] SeatList = request.QueryString["SeatList"].ToString().TrimEnd('|').Split('|');

            if (BLL.D_Area.Exists(SubCode))
            {
                if (SeatList.Length > 0)
                    for (int i = 0; i <= SeatList.Length - 1; i++)
                    {
                        BLL.D_SetSubArea.updateHide(SubCode, SeatList[i]);
                    }
            }
        }
        #endregion
    }
}
